﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PMSA.Framework.Log;

public partial class Admin_Uc_News_EditGroupNews : System.Web.UI.UserControl
{
    private int groupNewsId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Request.QueryString["gnid"] != null)
        {
            try
            {
                groupNewsId = int.Parse(Request.QueryString["gnid"].ToString());
            }
            catch
            {
                CLogManager.Write("GroupNews.Edit.PageLoad", "groupProducId not a number: " + Request.QueryString["gnid"].ToString(), "ADMIN");
            }
        }
        if (IsPostBack)
        {

        }
        else
        {
            GetDetailGroupNews(groupNewsId);
        }
    }

    private void GetDetailGroupNews(int groupNewsId)
    {
        try
        {
            GroupNews obj = new GroupNews();
            obj = obj.Detail(groupNewsId);
            txtGroupNewsName.Text = obj.Name;
            cbxGroupNewsActive.Checked = obj.Status == 1 ? true : false;
        }
        catch (Exception ex)
        {
            CLogManager.Write("GroupNews.Edit.GetDetailGroupNews", ex.ToString(), "ADMIN");
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            GroupNews obj = new GroupNews();
            obj = obj.Update(groupNewsId, txtGroupNewsName.Text, cbxGroupNewsActive.Checked ? 1 : 0);
            if (obj != null)
            {
                Response.Write("<script type='text/javascript'>alert('Edit Successful !');</script>");
            }
        }
        catch (Exception ex)
        {
            CLogManager.Write("GroupNews.Edit.btnEdit_Click", ex.ToString(), "ADMIN");
        }
    }
}